<template>
	<view class="content" style="background: url(../../static/diary/bg.png);background-size: 100%  100%;">
		<view class="btn" style="background: url(../../static/index/btn-one.png);background-size: 100%  100%;">
			我要复制到网盘下载
		</view>
		<view class="btn" style="background: url(../../static/index/btn-two.png);background-size: 100%  100%;">
			添加客服企业微信
		</view>
		<view class="help" @click="toHelp">
			<text>帮助</text>
			<text>中心</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				datalist: [],
				num: 0,
				userinfo: this.vuex_user,
				type: '',
				code: '',
				state: '',
				auth_url: undefined,
				showUserModal: false,
				genderModal: false,
				genderList: [{
						value: '1',
						label: '男'
					},
					{
						value: '2',
						label: '女'
					}
				],
				userInfoForm: {
					avatarUrl: null,
					nickName: null,
					gender: null,
					genderText: null,
				},
			};
		},
		async onLoad(e) {
			// #ifdef H5
			const url = await this.$u.api.getAuthUrl();
			this.auth_url = url;
			const weixin_code = this.getParam(location.href, 'code');
			if (weixin_code) {
				this.code = weixin_code;
				let wixinstate = this.getParam(location.href, 'state');
				this.state = wixinstate;
			}
			// #endif

			const {
				token
			} = e;
			if (token) {
				this.$u.vuex('vuex_token', token);

				const user_info = await this.$u.api.uinfo();
				this.$u.vuex('vuex_user', user_info);
			}
			this.list();
			if (e.type) {
				this.type = e.type;
			}

		},
		onShow() {},
		methods: {

			toHelp() {
				uni.navigateTo({
					url: '/pages/bangzhu/bangzhu'
				})
			},
			getParam(path, name) {
				var reg = new RegExp('(^|\\?|&)' + name + '=([^&]*)(\\s|&|$)', 'i');
				if (reg.test(path)) return unescape(RegExp.$2.replace(/\+/g, ' '));
				return '';
			},
			async list() {
				let res = await this.$u.api.setspaceurl();
				this.datalist = res;
				uni.setStorageSync('list', JSON.stringify(res));
			},
			gourl(e) {
				if (!this?.vuex_user?.nickname) {
					// #ifdef MP-TOUTIAO
					this.user().then(r => {
						this.$u.api.getUserInfo(r).then(re => {
							this.$u.vuex('vuex_user', re);
							uni.navigateTo({
								url: e
							});
						});
					});
					// #endif

					// #ifdef MP-WEIXIN
					if (!this.vuex_user.avatar) {
						this.showUserModal = true;
						return false;
					}
					// #endif

					// #ifdef H5
					window.location.href = this.auth_url;
					// #endif
				} else {
					uni.navigateTo({
						url: e
					});
				}
			},
			async select(item, e) {
				this.num = e;
			},
			onChooseNickanme(res) {
				if (res) {
					this.userInfoForm.nickName = res
				}
			},
			async onChooseAvatar(res) {
				const path = await this.uploader(res.detail.avatarUrl);
				this.userInfoForm.avatarUrl = path
			},
			genderConfirm(res) {
				this.userInfoForm.gender = res[0].value
				this.userInfoForm.genderText = res[0].label
				this.genderModal = false;
			},
			async submitUserInfo() {
				if (!this.userInfoForm.avatarUrl) {
					uni.showToast({
						title: '请选择头像',
						icon: 'none',
					});
					return false;
				}

				if (!this.userInfoForm.nickName) {
					uni.showToast({
						title: '请输入姓名',
						icon: 'none',
					});
					return false;
				}

				if (!this.userInfoForm.gender) {
					uni.showToast({
						title: '请选择性别',
						icon: 'none',
					});
					return false;
				}

				const user = await this.$u.api.getUserInfo(this.userInfoForm);
				this.$u.vuex('vuex_user', user);
				this.showUserModal = false;
			},
		}
	};
</script>

<style scoped>
	.content {
		width: 100%;
		height: 100vh;
	}

	.user-info-box {
		width: 100%;
		height: 600rpx;
		background-color: white;
		padding: 80rpx;
	}

	.avatar-wrapper {
		padding: 0;
		width: 56px !important;
		border-radius: 8px;
	}

	.avatar {
		display: block;
		width: 56px;
		height: 56px;
	}

	.btn {
		position: absolute;
		left: 50%;
		bottom: 250rpx;
		transform: translateX(-50%);
		width: 90%;
		height: 150rpx;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
	}

	.btn:nth-child(2) {
		bottom: 120rpx;
	}

	.help {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		color: #fff;
		width: 120rpx;
		height: 80rpx;
		font-size: 26rpx;
		border-top-left-radius: 40rpx;
		border-bottom-left-radius: 40rpx;
		background: linear-gradient(to right, #2991B6, #16CDDA);
		position: absolute;
		right: 0;
		top: 20vh;
	}
</style>